# coding=utf-8
import arcpy
path = r'D:\Test';
arcpy.env.workspace = path
bridge = r'D:\秋声科技\shp\雅安数据\bridge\bridge.shp'.decode('utf-8')
cs1 = arcpy.da.UpdateCursor(bridge,['SHAPE@','name','dis','mark'])

river = r'D:\秋声科技\shp\雅安数据\river\YA_RIV_LEVEL6_4326_0717.shp'.decode('utf-8')
cs2 = arcpy.da.SearchCursor(river,['SHAPE@','name','level','rivId'])
i = 0
for row in cs1:
    bridgePoint = row[0]
    disList = []
    for row2 in cs2:
        distans = row2[0].distanceTo(bridgePoint)
        nearestRivName = row2[1]
        res = [distans, nearestRivName,row2[3]]
        disList.append(res)
    cs2.reset()
    if(len(disList)>0):
        disList.sort(key=lambda x: x[0])
        print i,row[1],disList[0][1]
        i+=1
        row[2] = disList[0][0]
        row[3] = disList[0][1]
        cs1.updateRow(row)

